package com.zrj.pojo;

import org.apache.http.HttpStatus;

/**
 * 请求返回体
 *
 * @author qdm
 * @version 1.0
 * @date 2020/7/13 15:39
 */
public class Result<T> {
    private Integer code;

    private Boolean status;

    private T data;

    private String msg;

    public static Result error() {
        return new Result<>(HttpStatus.SC_INTERNAL_SERVER_ERROR, Boolean.FALSE, "请求异常", null);
    }

    public static Result error(int code, String msg) {
        return new Result<>(code, Boolean.FALSE, msg, null);
    }

    public static Result ok() {
        return new Result<>(HttpStatus.SC_OK, Boolean.TRUE, "请求成功", null);
    }

    public static Result ok(Object object) {
        return new Result<>(HttpStatus.SC_OK, Boolean.TRUE, "请求成功", object);
    }

    public static Result error(String message, Object object) {
        return new Result<>(HttpStatus.SC_INTERNAL_SERVER_ERROR, Boolean.FALSE, message, object);
    }
    public static Result error(String message) {
        return new Result<>(HttpStatus.SC_INTERNAL_SERVER_ERROR, Boolean.FALSE, message, null);
    }

    public static Result error(Object object) {
        return new Result<>(HttpStatus.SC_INTERNAL_SERVER_ERROR, Boolean.FALSE, "请求异常", object);
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Boolean isStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", status=" + status +
                ", data=" + data +
                ", msg='" + msg + '\'' +
                '}';
    }

    public Result(Integer code, Boolean status, String msg, T data) {
        this.code = code;
        this.status = status;
        this.data = data;
        this.msg = msg;
    }

    public Result() {
    }
}

